import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
const store = new Vuex.Store({
	state: {
		navbarTitle: "首页", //app的导航页标题
		isShowHead: true, //是否显示app 的导航栏
		isShowFoot: true, //是否显示foot栏
		isShowBack: true, //是否显示返回按钮
		isConnectionHub: false, //是否连接hubs
		locationInfo: {},
		skinColor:localStorage.getItem('skinColor')?localStorage.getItem('skinColor'):'rgba(33,217,162,1)',
		addGoodsNum: localStorage.getItem('cart')?JSON.parse(localStorage.getItem('cart')).length:0,
		cartList:localStorage.getItem('cart')?JSON.parse(localStorage.getItem('cart')):[],
		logined:localStorage.getItem('logined')=='true'?true:false
	},
	getters: {
		addGoodsNum: state => {
			return state.addGoodsNum;
		},
		cartList:state=>{
			return state.cartList;
		},
		logined:state=>{
			return state.logined;
		}
	},
	mutations: {
		updateLocationInfo(state, locationInfo) {
			state.locationInfo = locationInfo;
		},
		updateNavbarTitle(state, navbarTitle) {
			state.navbarTitle = navbarTitle;
		},
		updateNavbarStatus(state, {
			isShowHead = true,
			isShowFoot = true,
			isShowBack = true
		} = {}) {
			if (state.isShowHead != isShowHead) {
				state.isShowHead = isShowHead;
			}
			if (state.isShowFoot != isShowFoot) {
				state.isShowFoot = isShowFoot;
			}
			if (state.isShowBack != isShowBack) {
				state.isShowBack = isShowBack;
			}
		},
		updateConnectionHubStatus(state, isConnectionHub) {
			state.isConnectionHub = isConnectionHub;
		},
		updateAddGoodsNum(state, addGoodsNum) {
			state.addGoodsNum = addGoodsNum;
		},
		updateSkinColor(state,color){
			state.skinColor=color;
		},
		updateCartList(state,cartList){
			state.cartList=cartList;
		},
		updateLogined(state,logined){
			state.logined=logined;
		}
	},
	actions: {
		updateLocationInfo({
			commit
		}, locationInfo) {
			commit("updateLocationInfo", locationInfo);
		},
		updateNavbarTitle({
			commit
		}, navbarTitle) {
			commit("updateNavbarTitle", navbarTitle);
		},
		updateNavbarStatus({
			commit
		}, navbarStatusObject) {
			commit("updateNavbarStatus", navbarStatusObject);
		},
		updateConnectionHubStatus({
			commit
		}, isConnectionHub) {
			commit("updateConnectionHubStatus", isConnectionHub);
		},
		updateAddGoodsNum({
			commit
		}, addGoodsNum) {
			commit('updateAddGoodsNum', addGoodsNum)
		},
		updateSkinColor({commit},color){
			commit('updateSkinColor',color);
		},
		updateCartList({commit},cartList){
			commit('updateCartList',cartList)
		},
		updateLogined({commit},logined){
			commit('updateLogined',logined);
		}
	}
})
export default store;
